package com.k2data.Utils;

import java.util.ArrayList;
import java.util.List;

import com.k2data.platform.ddm.sdk.client.KMXClient;
import com.k2data.platform.ddm.sdk.client.KMXConfig;
import com.k2data.platform.ddm.sdk.common.DataType;
import com.k2data.platform.ddm.sdk.common.ParamNames;

public class Utils {
	private static List<String> ids = null;
	
	static {
		ids = new ArrayList<String>();
		ids.add("factory_id");
		ids.add("equipment_id");
		ids.add("machine_id");
		ids.add("datatype");
		ids.add("channel_type");
		ids.add("channel_id");
	}

	public static void waiting(long ms) {

		try {
			Thread.sleep(ms);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 
	 * @param id
	 * @return
	 */
	public static boolean isIdField(String id) {
		return ids.contains(id);
	}

	/**
	 * 
	 * @param url
	 * @param timeout
	 * @param dataType
	 * @return
	 */

	public static KMXClient kmxClient(String url, long timeout, DataType dataType) {
		KMXConfig config = new KMXConfig();
		config.put(ParamNames.PLATFORM_SERVER, url);
		config.put(ParamNames.SEND_TIMEOUT_MILLISECS, timeout);
		config.put(ParamNames.DATA_TYPE, dataType);
		return new KMXClient(config);
	}

	/**
	 * 
	 * @param channelType
	 * @return
	 */

	public static String getFgId(Integer channelType) {

		if (channelType == 0) {
			return Constants.FGNAME_VIB;
		} else if (channelType > 0) {
			return Constants.FGNAME_STA;
		}
		//
		else {
			System.out.println("Can not got fgId ,channelType :" + channelType);
			return null;
		}

	}

}
